import { createApp } from 'vue';
import './plugins/assets';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import 'viewerjs/dist/viewer.css'
import VueViewer from 'v-viewer'
import {
  setupAppVersionNotification,
  setupDayjs,
  setupIconifyOffline,
  setupLoading,
  setupNProgress,
  setupUI
} from './plugins';
import { setupStore } from './store';
import { setupRouter } from './router';
import { setupI18n } from './locales';

import App from './App.vue';
import admin from './admin';

try {
  window.$CodeSource = JSON.parse(localStorage.$CodeSource);
} catch (e) {
  window.$CodeSource = [];
}

async function setupApp() {
  setupLoading();

  setupNProgress();

  setupIconifyOffline();

  setupDayjs();

  const app = createApp(App);

  for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
  }

  setupUI(app);

  setupStore(app);

  await setupRouter(app);

  setupI18n(app);

  setupAppVersionNotification();

  app.use(admin);

  app.use(VueViewer, {
    defaultOptions: {
      zIndex: 9999
    }
  })

  app.mount('#app');
}

setupApp();
